//
//  PubInfoViewController.m
//  EPBPro
//
//  Created by wucha on 2018/7/16.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "PubInfoViewController.h"
#import "HttpHomeAction.h"
#import "ImageInfo.h"

@interface PubInfoViewController ()
@property (nonatomic,strong) NSArray *listArray;

@end

@implementation PubInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleName = @"资讯";
    self.tableView.separatorStyle = 0;
    [self loadPage];
}

-(void)loadPage{
    [HttpHomeAction getPubInfo:@"info" block:^(id result, NSError *error) {
        if (!error) {
            self.listArray = result;
            [self.tableView reloadData];
        }
    }];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
        UIImageView *imageView = [UIImageView new];
        imageView.tag = 10;
        [cell.contentView addSubview:imageView];
        imageView.sd_layout.leftSpaceToView(cell.contentView, 10).topSpaceToView(cell.contentView, 10).widthIs(100).heightIs(50);
        
        UILabel *titleLabel = [UILabel new];
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.numberOfLines = 0;
        titleLabel.tag = 11;
        [cell.contentView addSubview:titleLabel];
        titleLabel.sd_layout.leftSpaceToView(imageView, 10).topSpaceToView(cell.contentView, 10).rightSpaceToView(cell.contentView, 10).heightIs(50);
        
        UIView *lineView = [UIView new];
        lineView.backgroundColor = DefaultCellLineColor;
        [cell.contentView addSubview:lineView];
        lineView.sd_layout.leftSpaceToView(cell.contentView, 0).rightSpaceToView(cell.contentView, 0).bottomSpaceToView(cell.contentView, 0).heightIs(1);
    }
    // Configure the cell...
    UIImageView *imageView = [cell.contentView viewWithTag:10];
    ImageInfo *imageInfo = self.listArray[indexPath.row];
    [imageView sd_setImageWithURL:[NSURL URLWithString:imageInfo.imgUrl] placeholderImage:nil];
    
    UILabel *titleLabel = [cell.contentView viewWithTag:11];
    titleLabel.text = imageInfo.title;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
